import datetime
import os
import sys

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager

# 创建浏览器对象
class Driver:
    driver = ""
    def __init__(self):
        options = webdriver.ChromeOptions()
        self.driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()),options=options)
        self.driver.implicitly_wait(2)

    #生成屏幕截图
    def getScreeShot(self):
        #格式：2025-06-19-170211,然后存放在特定日期目录下
        dirname = datetime.datetime.now().strftime("%Y-%m-%d")
        if not os.path.exists("../images/"+dirname):
            os.mkdir("../images/"+dirname)

        filename = sys._getframe().f_back.f_code.co_name + datetime.datetime.now().strftime("%Y-%m-%d-%H%M%S")+".png"
        self.driver.save_screenshot("../images/"+dirname+"/"+filename)



WebDriver = Driver()
